/*
 * @lc app=leetcode.cn id=1496 lang=typescript
 *
 * [1496] 判断路径是否相交
 */

// @lc code=start
function isPathCrossing(path: string): boolean {
    let pos = [0, 0];
    const cache = new Set<string>(["0,0"]);
    for (let i = 0; i < path.length; i++) {
        const element = path[i];
        switch (element) {
            case "N":
                pos[1] += 1;
                break;
            case "S":
                pos[1] -= 1;
                break;
            case "E":
                pos[0] += 1;
                break;
            case "W":
                pos[0] -= 1;
                break;
        }
        if (cache.has(pos.join(","))) return true;
        cache.add(pos.join(","));
    }
    return false;
}
// @lc code=end
